<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="clearCookie()">清除cookie</button>
    <script>
        checkCookie()
        function setCookie(cname, cvalue, extime) {
            var extime = new Date.getDate(Date().getTime + 3600)
            document.cookie = cname + "='" + cvalue + "';" + extime
        }
        function checkCookie() {
            var cookie = document.cookie
            if (cookie) {
                var username = getCookie(cookie)
                alert("欢迎您的再次光临" + username)
            }
            else {
                var username = prompt("请输入您的用户名")
                setCookie("username", username, 3600)
            }
        }
        function getCookie(cookie) {
            var cvalue = cookie.split("'")[1]
            return cvalue
        }
        function clearCookie() {
            var end = Date().getTime - 8
            document.cookie = "expires=" + end

        }
    </script>
</body>

</html>